#include <windows.h>
#include "VfsManager.h"

using namespace SCL::VFS;

#ifdef _USRDLL

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	return TRUE;
}

extern "C" __declspec(dllexport) SCL::VFS::VfsManager* CreateVfsManager()
{
	return new SCL::VFS::VfsManager();
}

#endif	//	_USRDLL

#ifdef _DEBUG_EXE

#include <Vfs.h>

#include <scl_crc32.h>
#include <scl_sha1.h>
#include <scl_ary.h>

class A
{
public:
	A(){m_value = 7;}
	int m_value;
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	VfsManager *pVfsMgr = new VfsManager();
	{
		SCL::scl_ary<A> buffer(5);

		int v = buffer[0].m_value;
		//FILE *fw = NULL;
		//fopen_s(&fw, "crc32table.txt", "w");

		//SCL::AuxAlgorithm::CRC32TABLE pcrc32table = SCL::AuxAlgorithm::generate_crc32_table();

		//for (int i = 0; i < 32; ++i)
		//{
		//	for (int j=0; j < 8;++j)
		//	{
		//		char buf[30];
		//		sprintf_s(buf,"0x%08x, ",pcrc32table[i*8+j]);
		//	//	printf("0x=%x\n",pcrc32table[i]);
		//		fputs(buf,fw);
		//	}
		//	fputs("\r\n",fw);
		//}
		//SCL::AuxAlgorithm::destroy_crc32_table(pcrc32table);

		//fflush(fw);
		//fclose(fw);

		//FILE *fw = 0;
		//fopen_s(&fw, "test.txt", "w+b");
		//fseek(fw, 200, 0);
		//long i = ftell(fw);
		//fwrite("vfs-end", 7, 1, fw);
		//i = ftell(fw);
		//fclose(fw);

		//SCL::u32 crc32 = SCL::AuxAlgorithm::calc_crc32("abcd", 4);

		//SCL::u8	buf[20];
		//SCL::AuxAlgorithm::calc_sha1((SCL::u8*)"abcd", 4, buf);

		Vfs	*pVfs = pVfsMgr->CreateVFS(L"test.vfs");
		{
			pVfs->Login(L"s",L"s");
			if (!pVfs->Login(L"s",L"s"))
			{
				pVfs->ShowErrMsg();
			}
		}
		pVfs->Destroy();
	}
	delete pVfsMgr;

	return 0;
}

#endif	//	_DEBUG_EXE